package com.demo.xrom.ssh.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.xrom.ssh.entity.Person;
import com.demo.xrom.ssh.service.PersonService;
import com.smart.common.util.Page;
import com.smart.common.util.PageRequest;
import com.smart.tools.ObjectHelper;

/**
 * 
 * 版权所有：xxxxxxx
 * @Description: TODO
 * @Title: TestController.java 
 * @ClassName: TestController 
 * @author tangyan 
 * @date 2019年2月12日 下午2:49:38 
 * @version V1.0
 */
@Controller
public class TestController {

	
	Logger logger = LoggerFactory.getLogger(TestController.class);
	
    @Autowired
    private PersonService personService;

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test() {
        return "test";
    }

    @RequestMapping(value = "/savePerson", method = RequestMethod.GET)
    @ResponseBody
    public String savePerson() {
        personService.savePerson();
        return "success!";
    }
    
    @RequestMapping(value = "/queryPersonPage")
	@ResponseBody
	public String queryPersonPage(PageRequest pageRequest , String jsoncallback ,HttpServletRequest request) throws JsonGenerationException, JsonMappingException, IOException{
		//查询条件
		String  userName = request.getParameter("userName");
		Map<String, Object> conditions = new HashMap<String, Object>();
		conditions.put("username", userName);
		Page<Person> page =	personService.queryPersonPage(pageRequest, conditions);
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("total", page.getTotalRows());
		data.put("rows", page.getRecords());
		return ObjectHelper.objectToJson(data);
	}
  
}
